
<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
     <RouterLink
      to="/"
      class="goods-item"
      v-for="good in goodsList"
      :key="good.id"
    >
      <img :src="good.picture" alt="" />
      <p class="name ellipsis">{{ good.name }}</p>
      <p class="desc ellipsis">{{ good.desc }}</p>
      <p class="price">&yen;{{ good.price }}</p>
    </RouterLink>
  </div>
</template>
<script>
import { useRoute } from 'vue-router'
import { ref } from 'vue'
import { findHotGoods } from '@/api/goods'
export default {
  name: 'GoodsHot',
  props: {
    hotType: {
      type: Number,
      required: true
    }
  },
  setup (prop) {
    // 商品列表
    const route = useRoute()
    const goodsList = ref([])
    findHotGoods({ id: route.params.id, type: prop.hotType }).then(data => {
      goodsList.value = data.result
    })
    const title = ref('')
    const fn = () => {
      if (prop.hotType === 1) {
        title.value = '24小时热销榜'
      } else if (prop.hotType === 2) {
        title.value = '周热销榜'
      } else {
        title.value = '总热销榜'
      }
    }
    fn()
    return { goodsList, title }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
